﻿Imports MConfig

''' <summary>
''' DBコンフィグ
''' </summary>
''' <remarks>
''' ApplicationSettingsのラッパー</remarks>
Public Class DBConfig

    Private Shared _instance As DBConfig

    Private Sub New()
        'デコード処理を設定（任意）
        AddHandler MConfigReader.Instance.OnReadValue, AddressOf DecodeValue
    End Sub

    Public Shared Function Instance() As DBConfig
        If _instance Is Nothing Then
            _instance = New DBConfig
        End If
        Return _instance
    End Function

    Private ReadOnly Property Reader As MConfigReader
        Get
            Return MConfigReader.Instance
        End Get
    End Property

    Public ReadOnly Property Server As String
        Get
            Return Me.Reader.ReadValue("DB_SERVER")
        End Get
    End Property

    Public ReadOnly Property User As String
        Get
            Return Me.Reader.ReadValue("DB_USER")
        End Get
    End Property

    Public ReadOnly Property Password As String
        Get
            Return Me.Reader.ReadValue("DB_PASSWORD")
        End Get
    End Property

    Private Sub DecodeValue(sender As Object, e As SettingReadEventArgs)
        'リリース環境出ない、かつDB設定ではない場合、デコードしない
        If e.EnvironmentName <> "release" OrElse e.Tag.Contains("DB") = False Then
            Return
        End If

        e.Value = String.Format("*****{0}*****", e.Value)
        Return
    End Sub
End Class
